<?php
include '/var/www/html/new/com.inc.php';
include 'header.php';
$lid = intval($_GET['lid']);
$sql = <<<SQL
SELECT id,title,address,area,jtype,p_type,imgpath,px,jqts,bhjq,jtzn
FROM uu_land WHERE id=$lid LIMIT 1
SQL;
//echo $sql;
$GLOBALS['le']->query($sql);
$data = $GLOBALS['le']->fetch_assoc();

$_SESSION['shop_fid'] = $shop['fid'];
$Y_m_d = date('Y-m-d');
//分销商或供应商身份
if ($_SESSION['dtype']==0 || $_SESSION['dtype']==1) {
    include '/var/www/html/wx/api/v0.0.1/init.php';

    $tickets = $saveArr['tickets'][$lid];
}
else if(!$_SESSION['memberID'] || $_SESSION['dtype']==5) {
    if (!class_exists('SoapInit')) {
        include '/var/www/html/new/d/class/SoapInit.class.php';
        $soap = SoapInit::GetSoapInside();
    }
//    print_r($_SESSION);
    //未登录或散客身份
    $sqlTickets = <<<SQL
SELECT t.id as tid,t.title,t.pid,t.tprice,t.apply_did as aid,t.pay,t.getaddr,
t.notes as note,t.delaydays,t.ddays,f.dhour FROM uu_jq_ticket t
LEFT JOIN uu_land_f f ON t.id=f.tid WHERE landid=$lid
SQL;
    $GLOBALS['le']->query($sqlTickets);
    while ($row=$GLOBALS['le']->fetch_assoc()) {
//        print_r($row);
        //($ac, $pid, $date='', $mode=0, $ptype=0, $get_storage=0, $m)
//        echo $row['pid'] .'----' . $Y_m_d;
        if(($xml = $soap->Dynamic_Price_And_Storage('',$row['pid'],$Y_m_d,1,1,0,''))==105){
            $xml = $soap->Dynamic_Price_And_Storage('',$row['pid'],$Y_m_d,2,1,0,'');
        }
        if($xml==105) continue;
        $uprice = simplexml_load_string($xml)->Rec->UUsprice / 100;
        $row['bookTimeDay'] = $row['ddays'];
        $row['bookTimeHour']= $row['dhour'];
        $row['tprice']      = $row['tprice']*100 / 100;
        $row['uprice']      = $uprice ;
        $row['jsprice']     = $uprice ;
        $row['sapply_did']  = $row['aid'];
        //$_SESSION['apply_did']
//        $row['getaddr']     = $row['getaddr'];
//        $row['notes']       = $row['note'];
        $row['usetime']     = $row['delaydays']>0?
            "游玩日期起{$row['delaydays']}天内有效":"游玩日期当日有效";
        unset($row['delaydays']);
        $tickets[] = $row;
    }
}
//取'为您推荐'的产品 取销量最大的2个 max  销量最大
//取供应者
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$sql = "select apply_did from uu_land where id=$lid";
$le->query($sql);
$le->fetch_assoc();
$did = $le->f('apply_did');
//取他所有产品
$sql = "select id from uu_land where apply_did=$did";
$le->query($sql);
$r = array();
while($row=$le->fetch_assoc())
{$r[]=$row;}
//比较销量
$max1 = 1; $max2 = 0;
$max_lid1 =$max_lid2 = 'none';

foreach($r as $value){
    $x = $s->Order_Globle_Search("", "", $value['id'], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 1, 1, "0", "0", 1, "0", "", "0", "", "0", "", "", "", "0", "0", "0");
    // echo $x;exit;
    //先跟最大的比 比不过再跟第2大的比
    if($x>$max1){
        $max1=$x;$max_lid1=$value['id'];
    }elseif($x>$max2){
        $max2=$x;$max_lid2=$value['id'];
    }
}
$lids = array($max_lid1,$max_lid2);
foreach($lids as $lid){

    //取景区详情和价钱
    $sqlTickets = <<<SQL
SELECT id as tid,title,pid,tprice,landid
FROM uu_jq_ticket t
WHERE landid=$lid limit 1
SQL;
    $GLOBALS['le']->query($sqlTickets);
    while ($row=$GLOBALS['le']->fetch_assoc()) {
    $landid = $row['landid'];
    if(($xml = $s->Dynamic_Price_And_Storage('',$row['pid'],$Y_m_d,1,1,0,''))==105){
        $xml = $s->Dynamic_Price_And_Storage('',$row['pid'],$Y_m_d,2,1,0,'');
        }
        if($xml==105) continue;
        $uprice = simplexml_load_string($xml)->Rec->UUsprice / 100;
        $row['tprice']      = $row['tprice']*100 / 100;
        $row['uprice']      = $uprice ;
        $max_tickets[$row['landid']][] = $row;
    }
    //取出最便宜的票价
    $max_tickets[$landid]['min'] = min_by_key($max_tickets[$landid],'tprice');
    $sql = "select imgpath,title from uu_land where id=$landid limit 1";
    $le->query($sql);
    $le->fetch_assoc();
    $max_tickets[$landid]['imgpath'] = $le->f('imgpath');
    $max_tickets[$landid]['title'] = $le->f('title');
}
// print_r($max_tickets);
// exit;
//跟func.inc.php不同的是 124行 加了引号 能用小数做键名 不然小数就变0 了 那边没加引号也能取出小数 不知道为什么
function min_by_key($arr, $key){
        $min = array();
        foreach ($arr as $val) {
            if(!is_numeric($val[$key])) continue;
            if (!isset($val[$key]) and is_array($val)) {
                $min2 = min_by_key($val, $key); 
                $min[$min2] = 1;
            } elseif (!isset($val[$key]) and !is_array($val)) {
                return false;
            } elseif (isset($val[$key])) {
                $min["$val[$key]"] = 1;
            }
        }
        if(count($min)>0) {
            return min( array_keys($min) );
        }
        return 0;
    }
// var_dump($tickets);
// exit;
?>
<link rel="stylesheet" type="text/css" href="css/piao.css">
<div style="clear:both"></div>
</div>
</div>
    <div class="piao-list-title w1000">
        <div class="piao-list-title-left left">
            <h1><?=$data['title']?></h1>
            <p>地址：<?=$data['address']?> </p>
        </div>
      
    </div>
    <div style="clear: both"></div>
 
    <div class="mian-con w1000">
        <div class="main-con-left left">
            <div class="piao-type-list">
                <table cellpadding="0" cellspacing="0" border="0" id="piaolist">
                    <thead>
                        <tr>
                            <td class="td1">门票类型</td>
                            <td class="td2">景区价</td>
                            <td class="td3">优惠价</td>
                            <td class="td4">支付方式</td>
                            <td class="td5">取票方式</td>
                            <td class="td6">操作</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach($tickets as $ticket):?>
                        <tr>
                            <td class="t-type"><?=$ticket['title']?></td>
                            <td class="t-oriprice">￥<?=$ticket['tprice']?></td>
                            <td class="t-price">￥<?=$ticket['jsprice']?></td>
                             <td class="t-payway">
                             <font><?=$ticket['pay']==1 ? '在线支付':'景区现付'?></font>
                             </td>
                             <td class="t-way">
                             <font><?=$ticket['getaddr']?></font>
                             </td>
                             <td class="t-buy">
                                 <a href="buy.html?pid=<?=$ticket['pid']?>&aid=<?=$ticket['sapply_did']?>">预  定</a>
                             </td>
                        </tr>
                        <?php endforeach;?>
                    </tbody>
                </table>
            </div>
           
            <div class="piao-mess">
                <div class="piao-mess-title" position="fixed">
                    <ul> 
                        <li id="nav-jumpToNotice" class="nav-on"><a href="#yuding">预定须知</a></li>
                        <li id="nav-jumpToIntro"><a href="#xiangmu">项目介绍</a></li>
                        <li id="nav-jumpToTraffic"><a href="#jiaotong">交通指南</a></li>
                    </ul>
                    <div style="clear: both"></div>
                </div>

                <div class="piao-mess-item" id="ToNotice">
                    <h3 id="yuding">+ 预定须知</h3>
                    <div class="piao-mess-item-con ticketNotice"><?=nl2br($data['jdjs']);?></div>
                </div>

                <div class="piao-mess-item" id="ToIntro">
                    <h3 id="xiangmu">+ 项目介绍</h3>
                    <div class="piao-mess-item-con"><?=htmlspecialchars_decode($data['bhjq']);?></div>
                </div>

                <div class="piao-mess-item" id="ToTraffic">
                    <h3 id="jiaotong">+ 交通指南</h3>
                    <div   class="piao-mess-item-con"><?=nl2br($data['jtzn'])?></div>
                </div>
                <div style="clear: both"></div>
            </div>
        </div>
        <div class="main-con-right right">
			<style>
				.hot-article{margin-bottom:15px;}
				.hot-article ol{width: 250px;border: 1px solid #eee;overflow: hidden;padding-bottom:8px;padding-left:8px;}
				.hot-article ol li{font: normal 12px/22px 'MicroSoft Yahei';margin-top:10px;}
				.hot-article ol li a{font-size:14px;}
				.hot-article ol li a:hover{text-decoration:underline;color:#0069C4;}
				.hot-article ol li:hover span{transform: rotate(360deg);-webkit-transform: rotate(360deg);-ms-transform: rotate(360deg);-moz-transform: rotate(360deg);}
				.hot-article ol li span{display:inline-block;margin-right:8px;background: #ccc;width:22px;height: 22px;text-align: center;color: #fff;}
			</style>
            <div id="right" position="fixed" class="" style="top: 0px;">
                <h2 class="main-con-right-title">为您推荐</h2>
					<ul>
                        <?foreach($max_tickets as $recokey => $reco){?>
						<li>
							<dl>
								<dt><a href="detail.html?lid=<?=$recokey?>" title="<?=$reco['title']?>"><img src="http://www.12301.cc/<?=$reco['imgpath']?>" width="250" height="151" alt=""></a></dt>
								<dd class="tuijian-title"><?=$reco['title']?></dd>
								<dd class="tuijian-price">&yen<?=$reco['min']?>起<span>市场价:￥60</span></dd>
								<dd class="tuijian-btn"><a href="detail.html?lid=<?=$recokey?>" title="<?=$reco['title']?>"></a></dd>
							</dl>
						</li>
                        <?}?>						
					</ul>
            </div>
        </div>
        <div style="clear: both"></div>
    </div>
	   <div id="footer"><div class="footer-con">
			<div class="footer-con-center "></div>
			<div class="footer-con-right">
			   <p>24小时服务热线：0591-12301</p>
			</div>
	    </div>
	   </div>
	</body>

</html>